<?php

namespace app\adminapi\controller\v1\activity;

use app\adminapi\controller\AuthController;
use app\adminapi\export\ActivityExport;
use app\services\activity\ActivityService;
use think\facade\App;

class Activity extends AuthController
{
    protected $service;

    public function __construct(App $app, ActivityService $service)
    {
        parent::__construct($app);
        $this->service = $service;
    }


    public function index()
    {
        $params = $this->request->getMore([
            ['title', ''],
            ['cate_id', 0],
            ['activity_time', []],
            ['status', -1],
            ['time_status', -1],
            ['limit', 15]
        ]);
        return app('json')->success($this->service->getAdminList($params));
    }

    public function export()
    {
        $params = $this->request->getMore([
            ['title', ''],
            ['cate_id', 0],
            ['activity_time', []],
            ['status', -1],
            ['time_status', -1],
            ['limit', 15]
        ]);

        return app()->make(ActivityExport::class)->export($params);
    }


    public function detail($id)
    {
        return app('json')->success($this->service->detail($id));
    }

    public function save($id)
    {
        $data = $this->request->postMore([
            ['title', ''],
            ['start_time', 0],
            ['end_time', 0],
            ['status', 0],
            ['cate_id', []],
            ['type', 1],
            ['type_jifen', '0.00'],
            ['type_people', 0],
            ['comon_rate', 0],
            ['banner', ''],
            ['description', ''],
            ['content', '']
        ]);
        $this->service->save($id, $data);
        return app('json')->success(100021);
    }

    /**
     * 设置批量活动上架
     * @return mixed
     */
    public function activity_show()
    {
        [$ids] = $this->request->postMore([
            ['ids', []]
        ], true);
        $this->service->setShow($ids, 1);
        return app('json')->success(100014);
    }

    /**
     * 设置批量活动下架
     * @return mixed
     */
    public function activity_unshow()
    {
        [$ids] = $this->request->postMore([
            ['ids', []]
        ], true);
        $this->service->setShow($ids, 0);
        return app('json')->success(100014);
    }

    /**
     * 设置批量活动上架
     * @return mixed
     */
    public function activity_top()
    {
        [$ids] = $this->request->postMore([
            ['ids', []]
        ], true);
        $this->service->setTopStatus($ids, 1);
        return app('json')->success(100014);
    }

    /**
     * 设置批量活动下架
     * @return mixed
     */
    public function activity_down()
    {
        [$ids] = $this->request->postMore([
            ['ids', []]
        ], true);
        $this->service->setTopStatus($ids, 0);
        return app('json')->success(100014);
    }

    public function delete($id)
    {
        $this->service->delete($id);
        return app('json')->success(100002);
    }
}